var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var config = require('./webpack.config');

var app = new require('express')();
var port = 3000;
(function() {

  // Step 1: Create & configure a webpack compiler
  var webpack = require('webpack');
  var webpackConfig = require('./webpack.config');
  var compiler = webpack(webpackConfig);

  // Step 2: Attach the dev middleware to the compiler & the server
  app.use(require("webpack-dev-middleware")(compiler, {
    noInfo: true, publicPath: webpackConfig.output.publicPath
  }));

  // Step 3: Attach the hot middleware to the compiler & the server
  app.use(require("webpack-hot-middleware")(compiler, {
    log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000
  }));
})();

app.get("/", function(req, res) {
  res.sendFile(__dirname + '/index.html');
});
var http=require('http')
if (require.main === module) {
  var server = http.createServer(app);
  server.listen(process.env.PORT || port, function() {
    console.log("Listening on %j", "0.0.0.0");
  });
}

/*
app.listen(port, function(error) {
  if (error) {
    console.error(error);
  } else {
    console.info("==>  Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port);
  }
});
*/